package org.jeecgframework.web.controller;

import com.mybatis.ext.WiseCoreService;
import org.apache.log4j.Logger;
import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.exception.BusinessException;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.core.util.*;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.vo.TemplateExcelConstants;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.web.service.ZyCinemaServiceI;
import org.jeecgframework.web.system.pojo.base.*;
import org.jeecgframework.web.service.CbsAttachTaskServiceI;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.web.service.ZyCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author onlineGenerator
 * @version V1.0
 * @Title: Controller
 * @Description: 附加任务
 * @date 2017-12-22 15:01:52
 */
@Scope("prototype")
@Controller
@RequestMapping("/cbsAttachTaskController")
public class CbsAttachTaskController extends BaseController {
    /**
     * Logger for this class
     */
    private static final Logger logger = Logger.getLogger ( CbsAttachTaskController.class );

    @Autowired
    private CbsAttachTaskServiceI cbsAttachTaskService;
    @Autowired
    private SystemService systemService;
    @Autowired
    private ZyCinemaServiceI zyCinemaServiceI;
    @Autowired
    private ZyCommonService zyCommonService;
    @Autowired
    private CbsAttachTaskServiceI cbsAttachTaskServiceI;
    @Autowired
    private WiseCoreService wiseCoreService;
    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    /**
     * 附加任务列表 页面跳转
     *
     * @return
     */
    @RequestMapping(params = "cbsAttachTask")
    public ModelAndView cbsAttachTask(HttpServletRequest request) {
        request.setAttribute("attachTaskId",2);
        return new ModelAndView ( "com/zybk/cbsattachtask/cbsAttachTaskList" );
    }
    @RequestMapping(params = "getAttachTaskByCondition")
    public ModelAndView getAttachTaskByCondition(HttpServletRequest request) {
        String cinemaId = request.getParameter("cinemaId");
        String equipmentId = request.getParameter("equipmentId");
        List<CbsAttachTaskEntity> attachTaskByCondition = cbsAttachTaskService.getAttachTaskByCondition(cinemaId, equipmentId);
        System.out.println("---------"+attachTaskByCondition);
        return new ModelAndView ( "com/zybk/cbsattachtask/cbsAttachTaskList" );
    }

    @RequestMapping(params = "getAttachTaskByConditionByStatus")
    public ModelAndView getAttachTaskByConditionByStatus(HttpServletRequest request) {
        String cinemaId = request.getParameter("cinemaId");
        String equipmentId = request.getParameter("equipmentId");
        List<Map<String, Object>> attachTaskByCondition = cbsAttachTaskService.getAttachTaskByConditionByStatus(cinemaId, equipmentId);
        System.out.println("---------"+attachTaskByCondition);
        return new ModelAndView ( "com/zybk/cbsattachtask/cbsAttachTaskList" );
    }
    /**
     * easyui AJAX请求数据
     *
     * @param request
     * @param response
     * @param dataGrid
     * @param user
     */

    @RequestMapping(params = "datagrid")
    public void datagrid(CbsAttachTaskEntity cbsAttachTask, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {

        CriteriaQuery cq = new CriteriaQuery ( CbsAttachTaskEntity.class, dataGrid );
        //查询条件组装器
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, cbsAttachTask, request.getParameterMap () );
        try {
            //自定义追加查询条件
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        cq.add ();
         this.cbsAttachTaskService.getDataGridReturn(cq, true);
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * 附加任务新增页面跳转
     *
     * @return
     */
    @RequestMapping(params = "goAdd")
    public ModelAndView goAdd(CbsAttachTaskEntity cbsAttachTask, HttpServletRequest req) {
        List<ZyCinemaEntity> zyCinemaEntitys = zyCinemaServiceI.getList(ZyCinemaEntity.class);
        req.setAttribute ( "zyCinemaEntitys", zyCinemaEntitys );
        if (StringUtil.isNotEmpty ( cbsAttachTask.getId () )) {
            cbsAttachTask = cbsAttachTaskService.getEntity ( CbsAttachTaskEntity.class, cbsAttachTask.getId () );
            req.setAttribute ( "cbsAttachTaskPage", cbsAttachTask );

        }
        return new ModelAndView ( "com/zybk/cbsattachtask/cbsAttachTask-add" );
    }


    /**
     * 添加附加任务
     *
     * @param ids
     * @return
     */
    @RequestMapping(params = "doAdd")
    @ResponseBody
    public AjaxJson doAdd(CbsAttachTaskEntity cbsAttachTask, HttpServletRequest request) throws UnsupportedEncodingException {
        String ids  = request.getParameter("id");
        String id = null;
        String contents  = request.getParameter("content");
        String equipmentId = request.getParameter("equipment");
         if (ids!=null){
             id= URLDecoder.decode(ids, "UTF-8");
         }
        String content = URLDecoder.decode(contents, "UTF-8");
        ZyCinemaEntity zyCinemaEntity2 = null;
        if (id!=null&&id!=""){
            String hql = "from ZyCinemaEntity where name = '"+id+"'";
             zyCinemaEntity2 = zyCommonService.singleResult(hql);
        }

        ZyEquipmentSpareEntity zyEquipmentSpareEntity1 = null;
        if (equipmentId!=null){
            String findSNhql = " from ZyEquipmentSpareEntity where sn = '"+equipmentId+"'";
            zyEquipmentSpareEntity1 = zyCommonService.singleResult(findSNhql);
        }

        ZyEquipmentSpareEntity zyEquipmentSpareEntity = new ZyEquipmentSpareEntity();
        ZyCinemaEntity zyCinemaEntity = new ZyCinemaEntity();
        if (id=="" || id ==null &&equipmentId==null || equipmentId==""){
            zyCinemaEntity.setId("0");
            zyEquipmentSpareEntity.setId("");
            cbsAttachTask.setCinemaId(null);
            cbsAttachTask.setEquipmentId(null);
            cbsAttachTask.setObjectName("其他");
        }
        if (id!=null&&id!=""){
            zyCinemaEntity.setId(zyCinemaEntity2.getId());
            zyEquipmentSpareEntity.setId("");
            cbsAttachTask.setCinemaId(zyCinemaEntity);
            cbsAttachTask.setEquipmentId(null);
            cbsAttachTask.setObjectName(id);
        }
        if (equipmentId!=null){
            zyEquipmentSpareEntity.setId(zyEquipmentSpareEntity1.getId());
            zyCinemaEntity.setId("0");
            cbsAttachTask.setEquipmentId(zyEquipmentSpareEntity);
            cbsAttachTask.setCinemaId(null);
            cbsAttachTask.setObjectName(equipmentId);
        }
        cbsAttachTask.setContent(content);
        cbsAttachTask.setStatus("1");
        cbsAttachTask.setAssignmentTotal(0);
        cbsAttachTask.setNotCompleteTotal(0);
        cbsAttachTask.setCompleteTotal(0);
        AjaxJson j = new AjaxJson ();
        message = "附加任务添加成功";
        try {

            cbsAttachTaskService.save ( cbsAttachTask );
            systemService.addLog ( message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO );
        } catch (Exception e) {
            e.printStackTrace ();
            message = "附加任务添加失败";
            throw new BusinessException ( e.getMessage () );
        }
        j.setMsg ( message );
        return j;
    }

    /**
     * 跳转界面
     * @param request
     * @return
     */
    @RequestMapping(params = "zyChooseSnOfContact")
    public ModelAndView zyChooseCmOfContact(HttpServletRequest request) {
        return new ModelAndView("com/zybk/cbsattachtask/zyChooseSnOfContact");
    }

    /**
     * 选择设备序列号
     * @param zyEquipmentSpareEntity
     * @param request
     * @param response
     * @param dataGrid
     */
    @RequestMapping(params = "datagridOfChooseSnOfContact")
    public void datagridOfChooseCmOfContact(ZyEquipmentSpareEntity zyEquipmentSpareEntity,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery(ZyEquipmentSpareEntity.class, dataGrid);
        //查询条件组装器
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, zyEquipmentSpareEntity, request.getParameterMap());

        try{
            //自定义追加查询条件
        }catch (Exception e) {
            throw new BusinessException(e.getMessage());
        }
        cq.add();
        this.cbsAttachTaskService.getDataGridReturn(cq, true);
        TagUtil.datagrid(response, dataGrid);
    }
    /**
     * 附加任务编辑页面跳转
     *
     * @return
     */
    @RequestMapping(params = "goUpdate")
    public ModelAndView goUpdate(CbsAttachTaskEntity cbsAttachTask, HttpServletRequest req) {
        if (StringUtil.isNotEmpty ( cbsAttachTask.getId () )) {
            cbsAttachTask = cbsAttachTaskService.getEntity ( CbsAttachTaskEntity.class, cbsAttachTask.getId () );
            req.setAttribute ( "cbsAttachTaskPage", cbsAttachTask );
        }
        return new ModelAndView ( "com/zybk/cbsattachtask/cbsAttachTask-update" );
    }
    @RequestMapping(params = "goUpdateRemarks")
    public ModelAndView goUpdateRemarks(CbsAttachTaskEntity cbsAttachTask, HttpServletRequest req) {
        if (StringUtil.isNotEmpty ( cbsAttachTask.getId () )) {
            cbsAttachTask = cbsAttachTaskService.getEntity ( CbsAttachTaskEntity.class, cbsAttachTask.getId () );
            req.setAttribute ( "cbsAttachTaskPage", cbsAttachTask );
        }
        return new ModelAndView ( "com/zybk/cbsattachtask/cbsAttachTask-updateRemarks" );
    }
    /**
     * 更新附加任务
     *
     * @param ids
     * @return
     */
    @RequestMapping(params = "doUpdate")
    @ResponseBody
    public AjaxJson doUpdate(CbsAttachTaskEntity cbsAttachTask, HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        message = "附加任务更新成功";

        CbsAttachTaskEntity t = cbsAttachTaskService.get ( CbsAttachTaskEntity.class, cbsAttachTask.getId () );
        try {
            MyBeanUtils.copyBeanNotNull2Bean ( cbsAttachTask, t );
            cbsAttachTaskService.saveOrUpdate ( t );
            systemService.addLog ( message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO );
        } catch (Exception e) {
            e.printStackTrace ();
            message = "附加任务更新失败";
            throw new BusinessException ( e.getMessage () );
        }
        j.setMsg ( message );
        return j;
    }


    /**
     * 删除附加任务
     *
     * @return
     */
    @RequestMapping(params = "doDel")
    @ResponseBody
    public AjaxJson doDel(CbsAttachTaskEntity cbsAttachTask, HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        cbsAttachTask = systemService.getEntity ( CbsAttachTaskEntity.class, cbsAttachTask.getId () );
        message = "附加任务删除成功";
        try {
            cbsAttachTaskService.delete ( cbsAttachTask );
            systemService.addLog ( message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO );
        } catch (Exception e) {
            e.printStackTrace ();
            message = "附加任务删除失败";
            throw new BusinessException ( e.getMessage () );
        }
        j.setMsg ( message );
        return j;
    }

    /**
     * 批量删除附加任务
     *
     * @return
     */
    @RequestMapping(params = "doBatchDel")
    @ResponseBody
    public AjaxJson doBatchDel(String ids, HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        message = "附加任务删除成功";
        try {
            for (String id : ids.split ( "," )) {
                CbsAttachTaskEntity cbsAttachTask = systemService.getEntity ( CbsAttachTaskEntity.class,
                        id
                );
                cbsAttachTaskService.delete ( cbsAttachTask );
                systemService.addLog ( message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO );
            }
        } catch (Exception e) {
            e.printStackTrace ();
            message = "附加任务删除失败";
            throw new BusinessException ( e.getMessage () );
        }
        j.setMsg ( message );
        return j;
    }

    /**
     * 导入功能跳转
     *
     * @return
     */
    @RequestMapping(params = "upload")
    public ModelAndView upload(HttpServletRequest req) {
        return new ModelAndView ( "com/zybk/cbsattachtask/cbsAttachTaskUpload" );
    }
    /**
     * 附加任务导出
     *
     * @param request
     * @param response
     */
    @RequestMapping(params = "exportAttachTaskInspectionPlan")
    public void exportAttachTaskInspectionPlan(HttpServletRequest request, HttpServletResponse response) {
        cbsAttachTaskService.exportAttachTaskInspectionPlan(request, response);
    }
    /**
     * 导出excel
     *
     * @param request
     * @param response
     */
    @RequestMapping(params = "exportXls")
    public String exportXls(CbsAttachTaskEntity cbsAttachTask, HttpServletRequest request, HttpServletResponse response
            , DataGrid dataGrid, ModelMap modelMap) throws ParseException {
        TSUser user = ResourceUtil.getSessionUserName();
        CriteriaQuery cq = new CriteriaQuery ( CbsAttachTaskEntity.class, dataGrid );
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, cbsAttachTask, request.getParameterMap () );
        List<CbsAttachTaskEntity> cbsAttachTasks = this.cbsAttachTaskService.getListByCriteriaQuery ( cq, false );
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i =0;i<cbsAttachTasks.size();i++){
            if (cbsAttachTasks.get(i).getStatus().equals("1")){
                cbsAttachTasks.get(i).setStatus("待处理");

            }
            if (cbsAttachTasks.get(i).getStatus().equals("2")){
                cbsAttachTasks.get(i).setStatus("进行中");
            }
            if (cbsAttachTasks.get(i).getStatus().equals("3")){
                cbsAttachTasks.get(i).setStatus("已完成");
            }
            if (cbsAttachTasks.get(i).getStatus().equals("4")){
                cbsAttachTasks.get(i).setStatus("已取消");
            }
            if (cbsAttachTasks.get(i).getCreateDate()!=null){
                String format = sdf.format(cbsAttachTasks.get(i).getCreateDate());
                cbsAttachTasks.get(i).setCreateDate1(format);
            }

            if (cbsAttachTasks.get(i).getUpdateDate()!=null){
                String format1 = sdf.format(cbsAttachTasks.get(i).getUpdateDate());
                cbsAttachTasks.get(i).setUpdateDate1(format1);
            }



        }
        modelMap.put ( NormalExcelConstants.FILE_NAME, "附加任务" );
        modelMap.put ( NormalExcelConstants.CLASS, CbsAttachTaskEntity.class );
        modelMap.put ( NormalExcelConstants.PARAMS, new ExportParams ( "附加任务列表", "导出人:" + ResourceUtil.getSessionUserName ().getRealName (),
                "导出信息" ) );
        modelMap.put ( NormalExcelConstants.DATA_LIST, cbsAttachTasks );
        systemService.addLog(user.getRealName()+"导出"+cbsAttachTasks.size()+"条附加任务记录", Globals.Log_Type_OTHER, Globals.Log_Leavel_INFO);
        return NormalExcelConstants.JEECG_EXCEL_VIEW;
    }

    /**
     * 导出excel 使模板
     *
     * @param request
     * @param response
     */
    @RequestMapping(params = "exportXlsByT")
    public String exportXlsByT(CbsAttachTaskEntity cbsAttachTask, HttpServletRequest request, HttpServletResponse response
            , DataGrid dataGrid, ModelMap modelMap) {
        modelMap.put ( TemplateExcelConstants.FILE_NAME, "附加任务" );
        modelMap.put ( TemplateExcelConstants.PARAMS, new TemplateExportParams ( "Excel模板地址" ) );
        modelMap.put ( TemplateExcelConstants.MAP_DATA, null );
        modelMap.put ( TemplateExcelConstants.CLASS, CbsAttachTaskEntity.class );
        modelMap.put ( TemplateExcelConstants.LIST_DATA, null );
        return TemplateExcelConstants.JEECG_TEMPLATE_EXCEL_VIEW;
    }

    @SuppressWarnings("unchecked")
    @RequestMapping(params = "importExcel", method = RequestMethod.POST)
    @ResponseBody
    public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
        AjaxJson j = new AjaxJson ();

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap ();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet ()) {
            MultipartFile file = entity.getValue ();// 获取上传文件对象
            ImportParams params = new ImportParams ();
            params.setTitleRows ( 2 );
            params.setHeadRows ( 1 );
            params.setNeedSave ( true );
            try {
                List<CbsAttachTaskEntity> listCbsAttachTaskEntitys = ExcelImportUtil.importExcelByIs ( file.getInputStream (), CbsAttachTaskEntity.class, params );
                for (CbsAttachTaskEntity cbsAttachTask : listCbsAttachTaskEntitys) {
                    cbsAttachTaskService.save ( cbsAttachTask );
                }
                j.setMsg ( "文件导入成功！" );
            } catch (Exception e) {
                j.setMsg ( "文件导入失败！" );
                logger.error ( ExceptionUtil.getExceptionMessage ( e ) );
            } finally {
                try {
                    file.getInputStream ().close ();
                } catch (IOException e) {
                    e.printStackTrace ();
                }
            }
        }
        return j;
    }

    /**
     * 拼接字符串
     * @param str
     * @return
     */
    public String spiltAppend(String str) {
        StringBuffer sb = new StringBuffer();
        String[] temp = str.split(",");
        for (int i = 0; i < temp.length; i++) {
            if (!"".equals(temp[i]) && temp[i] != null)
                sb.append("'" + temp[i] + "',");
        }
        String result = sb.toString();
        String tp = result.substring(result.length() - 1, result.length());
        if (",".equals(tp))
            return result.substring(0, result.length() - 1);
        else
            return result;
    }
    /**
     * 通过点击分派次数进入服务单
     * @param request
     */
    @RequestMapping(params = "goServiceByFP")
    public ModelAndView goServiceByFP(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, HttpSession session){
        try {
            String id = request.getParameter("id");
            List<CbsServiceTaskMapEntity> cbsServiceTaskMapEntityList = systemService.findHql("from CbsServiceTaskMapEntity where attachTaskId.id='"+id+"' and type IS NULL");
            StringBuffer stringBuffer = new StringBuffer();
            for (int i=0;i<cbsServiceTaskMapEntityList.size();i++){
               stringBuffer.append(cbsServiceTaskMapEntityList.get(i).getServiceId().getId());
               stringBuffer.append(",");
           }
            String str = stringBuffer.toString();
            if (!str.equals("")){
                String s = spiltAppend(str);
                session.setAttribute("attachTaskId",s);
            }else{
                session.setAttribute("attachTaskId",str);
            }

        }catch (Exception e){
            e.getMessage();
        }
        return new ModelAndView("com/zybk/cbsattachtask/cbsServiceList");
    }
    /**
     * 通过点击完成次数进入服务单
     * @param request
     */
    @RequestMapping(params = "goServiceByCompleted")
    public ModelAndView goServiceByCompleted(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, HttpSession session){
        try {
            String id = request.getParameter("id");
            List<CbsServiceTaskMapEntity> cbsServiceTaskMapEntityList = systemService.findHql("from CbsServiceTaskMapEntity where attachTaskId.id='"+id+"' and type ='ywc'");
            systemService.findForJdbc("SELECT * from cbs_service_task_map where attach_task_id = '"+id+"' and type = 'ywc' ");
            StringBuffer stringBuffer = new StringBuffer();
            for (int i=0;i<cbsServiceTaskMapEntityList.size();i++){
                stringBuffer.append(cbsServiceTaskMapEntityList.get(i).getServiceId().getId());
                stringBuffer.append(",");
            }
            String str = stringBuffer.toString();
            if (!str.equals("")){
                String s = spiltAppend(str);
                session.setAttribute("attachTaskId",s);
            }else{
                session.setAttribute("attachTaskId",str);
            }
        }catch (Exception e){
            e.getMessage();
        }
        return new ModelAndView("com/zybk/cbsattachtask/cbsServiceList");
    }

    /**
     * 通过点击未完成次数进入服务单
     * @param request
     */
    @RequestMapping(params = "goServiceByNotCompleted")
    public ModelAndView goServiceByNotCompleted(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, HttpSession session){
        try {
            String id = request.getParameter("id");
            List<CbsServiceTaskMapEntity> cbsServiceTaskMapEntityList = systemService.findHql("from CbsServiceTaskMapEntity where attachTaskId.id='"+id+"' and type ='wwc'");
            StringBuffer stringBuffer = new StringBuffer();
            for (int i=0;i<cbsServiceTaskMapEntityList.size();i++){
                stringBuffer.append(cbsServiceTaskMapEntityList.get(i).getServiceId().getId());
                stringBuffer.append(",");
            }
            String str = stringBuffer.toString();
            if (!str.equals("")){
                String s = spiltAppend(str);
                session.setAttribute("attachTaskId",s);
            }else{
                session.setAttribute("attachTaskId",str);
            }
        }catch (Exception e){
            e.getMessage();
        }
        return new ModelAndView("com/zybk/cbsattachtask/cbsServiceList");
    }
    /**
     * easyui AJAX请求数据
     *
     * @param request
     * @param response
     * @param dataGrid
     * @param
     */

    @RequestMapping(params = "datagridByCount")
    public void datagridByCount(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid,HttpSession session) {
        Map param = new HashMap<>();
        String attachTaskId = (String) session.getAttribute("attachTaskId");
        System.out.println(attachTaskId);
        for (Object key : request.getParameterMap().keySet()) {
            if ((String[]) request.getParameterMap().get(key) != null) {
                for (int i = 0; i < ((String[]) request.getParameterMap().get(key)).length; i++) {
                    if (((String[]) request.getParameterMap().get(key))[i] != null) {
                        param.put(key, ((String[]) request.getParameterMap().get(key))[i].trim());
                    }
                }
            }
        }
        if (!StringUtil.isEmpty(oConvertUtils.getString(param.get("createDate_begin")))) {
            param.put("createDate_begin", oConvertUtils.getString(param.get("createDate_begin")) + " 00:00:01");
        }
        if (!StringUtil.isEmpty(oConvertUtils.getString(param.get("createDate_end")))) {
            param.put("createDate_end", oConvertUtils.getString(param.get("createDate_end")) + " 23:59:59");
        }
        if (!StringUtil.isEmpty(oConvertUtils.getString(param.get("closeTime_begin")))) {
            param.put("closeTime_begin", oConvertUtils.getString(param.get("closeTime_begin")) + " 00:00:01");
        }
        if (!StringUtil.isEmpty(oConvertUtils.getString(param.get("closeTime_end")))) {
            param.put("closeTime_end", oConvertUtils.getString(param.get("closeTime_end")) + " 23:59:59");
        }
            if(!attachTaskId.equals("")){
                String substring = attachTaskId.substring(1,attachTaskId.length() - 1);
                if (!StringUtil.isEmpty(attachTaskId)) {
                    param.put("attachTaskId", substring);
                }

            }else {
                param.put("attachTaskId", null);
            }

        wiseCoreService.selectDataGrid("selectServiceDatagridByAttachTask", param, dataGrid);
        TagUtil.datagrid(response, dataGrid);
    }
}
